package com.cn.crmsystem.service.approveService.impl;

import com.cn.crmsystem.mapper.approveMapper.ReturnMapper;
import com.cn.crmsystem.pojo.Approve;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.approveService.ReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReturnImpl implements ReturnService{
	@Autowired ReturnMapper returnMapper;
	//全查
	@Override
	public ResultJson ReturnSelect(Integer userid) {
		List<Approve> list=new ArrayList<>();
		ResultJson resultJson=new ResultJson();
		Map<String,Object> map=new HashMap<>();
		list=returnMapper.selectAll(userid);
		String msg;
      if(list!=null){
		msg="成功了";
      	map.put("全查",list);
		resultJson.getSuccess(msg,map);
	  }else{
		  msg="失 败";
		  resultJson.getFail(msg);
	  }
		return resultJson;
	}
   //修改
	@Override
	public ResultJson UpdateReturn(Integer appid, Integer state) {
		ResultJson resultJson=new ResultJson();
		String code;
		String msg;
	if(returnMapper.UpdateApproveReturn(appid,state)>0) {
		code="200";
		msg = "成功";
		resultJson.getSuccess(msg,code);
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		return resultJson;
	}
   //删除
	@Override
	public ResultJson DeleteReturn(Integer appid) {
		ResultJson resultJson=new ResultJson();
		String code;
		String msg;
		if(returnMapper.DeleteApprove(appid)>0) {
			Integer c=returnMapper.SelectDataid(appid);
			if(c>0){
				Integer d=returnMapper.DeleteReturn(c);
				if(d>0){
					code="200";
					msg = "成 功";
					 resultJson.getSuccess(msg,code);
				}else {
					msg="失败";
					resultJson.getSuccess(msg);
				}
			}else {
				msg="失败";
				resultJson.getSuccess(msg);
			}
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		return resultJson;
	}
	//条件查询
	@Override
	public ResultJson SelectConditionRturn(Integer userid, Integer state) {
		List<Approve> list=new ArrayList<>();
		ResultJson resultJson=new ResultJson();
		Map<String,Object> map=new HashMap<>();
		if(state==0){
			list=returnMapper.selectConditionReturn(userid,state);
		}else {
			list=returnMapper.selectConditionTwoReturn(userid);
		}
		String msg;
		if (list!=null){
			msg = "成功";
			map.put("条件查询",list);
			resultJson.getSuccess(msg,map);
		}else{
			msg="失败";
			resultJson.getSuccess(msg);
		}
		return resultJson;
	}
}
